/**
 * File TestFileToSendModel.java 
 */
package cstest.model;

import static org.junit.Assert.*;

import java.io.File;
import java.net.InetAddress;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import cs.entity.User;
import cs.entity.UserFile;
import cs.entity.UserFile.State;
import cs.model.FileToSendModel;

/**
 * Package  cstest.model
 * Project ChatSystemG1 - INSA 4INFOA1 - 2013/2014
 * @author Julie DUMONS & Juste OUEDRAOGO
 *
 */
public class TestFileToSendModel {

	FileToSendModel ftsm1, ftsm2 ; 
	UserFile uf1, uf2, uf3, uf4 ; 
	
	/**
	 * @throws java.lang.Exception
	 */
	@Before
	public void setUp() throws Exception {
		ftsm2 = new FileToSendModel() ; 
		uf1 = new UserFile(new User("username1",InetAddress.getByName("127.0.0.1")), new File("test1.txt")); 
		uf2 = new UserFile(new User("username2",InetAddress.getByName("127.0.0.2")), new File("test2.txt")); 
		uf3 = new UserFile(new User("username3",InetAddress.getByName("127.0.0.3")), new File("test3.txt")); 
		uf4 = new UserFile(new User("username4",InetAddress.getByName("127.0.0.4")), new File("test4.txt")); 
		ftsm2.addFileToSend(uf4);
	}

	/**
	 * @throws java.lang.Exception
	 */
	@After
	public void tearDown() throws Exception {
		ftsm2 = null ;
		uf1 = null ; 
		uf2 = null ;
		uf3 = null ;
	}

	/**
	 * Test method for {@link cs.model.FileToSendModel#FileToSendModel()}.
	 */
	@Test
	public void testFileToSendModel() {
		ftsm1 = new FileToSendModel() ; 
		assertNotNull(ftsm1) ; 
		
	}

	/**
	 * Test method for {@link cs.model.FileToSendModel#addFileToSend(cs.entity.UserFile)}.
	 */
	@Test
	public void testAddFileToSend() {
		ftsm2.addFileToSend(uf1); 
		assertNotNull(ftsm2.getFile(uf1)); 
		ftsm2.addFileToSend(uf2); 
		ftsm2.addFileToSend(null);
	}

	/**
	 * Test method for {@link cs.model.FileToSendModel#getFile(cs.entity.UserFile)}.
	 */
	@Test
	public void testGetFile() {
		ftsm2.addFileToSend(uf1); 
		ftsm2.addFileToSend(uf2); 
		assertNull(ftsm2.getFile(uf3)); 
		assertNotNull(ftsm2.getFile(uf2)); 
		assertNotNull(ftsm2.getFile(uf1)); 
		ftsm2.addFileToSend(uf3); 
		assertNotNull(ftsm2.getFile(uf3)); 
	}

	/**
	 * Test method for {@link cs.model.FileToSendModel#setFileState(cs.entity.UserFile, cs.entity.UserFile.State)}.
	 */
	@Test
	public void testSetFileState() {		
		assertSame(uf4.getState(),State.REQUEST);
		ftsm2.setFileState(uf4, State.FAILED);
		assertSame(uf4.getState(), State.FAILED);
		
	}

	/**
	 * Test method for {@link cs.model.FileToSendModel#removeFile(cs.entity.UserFile)}.
	 */
	@Test
	public void testRemoveFile() {
		ftsm2.addFileToSend(uf1); 
		ftsm2.addFileToSend(uf2); 
		assertNotNull(ftsm2.getFile(uf2)); 
		assertNotNull(ftsm2.getFile(uf1)); 
		ftsm2.removeFile(uf2);
		assertNull(ftsm2.getFile(uf2)); 
	}

}
